﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AttributeListPage.aspx.cs" Inherits="Easy.Web.Pages.EntityPages.AttributeListPage" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head id="Head1" runat="server">
    <title></title>
    <link href="/_css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/_css/common.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/_css/iconfont.css" />
    <script src="/_js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/_js/bootstrap.min.js" type="text/javascript"></script>
    <script src="/_js/json2.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {

            GetAttributeList();

            GetNNRelationship();

            GetViewList();

            GetFormList();


            $("#showModal_btn").click(function () {
                setTimeout("$('#myModal2').modal('show')", 500);
            });

            $("#showModal_btn2").click(function () {
                setTimeout("$('#myModal3').modal('show')", 500);
            });

            $("#showModal_btn3").click(function () {

                btn_Del(Name, Type);
            });

        });


        function GetAttributeList() {
            $.ajax({
                url: "/Service/Entity/GetAttributeList.ashx",
                async: false,
                type: "post",
                dataType: "JSON",
                data: {
                    "entityid": $("#entityid").val()

                },
                success: function (data, textStatus) {

                    var SMShtml = "<table class='table table-hover'>"
                        + " <thead><tr><th>#</th><th>字段英文名</th><th>字段显示名称"
                                           + "  </th><th>字段创建时间</th><th>字段类型</th>"
                                            + "<th>字段长度</th><th>需求级别</th>"
                                              + "<th>可搜索</th><th>自定义字段</th><th>操作</th><th>删除</th>"                    //zw
                                           + "</tr></thead><tbody>";

                    for (var i = 0; i < data.length; i++) {
                        var item = data[i];
                        SMShtml += "<tr  name='list' id=\"" + (i + 1) + "\">"
                        /*NO*/ + "<td>" + (i + 1) + "</td>"
                    + "<td  id=\"list" + (i + 1) + "\">" + item.name + "</td>"
                    + "<td   id=\"list" + (i + 1) + "\">" + item.DisplayName + "</td>"
                    + "<td   id=\"list" + (i + 1) + "\">" + item.CreatedOn + "</td>"
                     + "<td   id=\"list" + (i + 1) + "\">" + item.type + "</td>"
                     + "<td   id=\"list" + (i + 1) + "\">" + item.length + "</td>"
                     + "<td   id=\"list" + (i + 1) + "\">" + item.IsNullable + "</td>"
                     + "<td   id=\"list" + (i + 1) + "\">" + item.Cansearchable + "</td>"
                     + "<td   id=\"list" + (i + 1) + "\">" + item.IsSystemAtt + "</td>"
                     + "<td   id=\"list" + (i + 1) + "\"><button type='button' onclick='btn_openDetail(\"" + item.AttributeMapId + "\");' class='btn btn-primary ng-binding'>查看</button></td>";

                        if (item.IsSystemAtt == "否") {
                            SMShtml += "<td   id=\"list" + (i + 1) + "\"><a  role='button' class='btn btn-warning'href='#myModal'data-toggle='modal' data-target='#myModal' onclick='btn_keep(\"" + item.name + "\",\"" + item.type + "\");'>删除</a></td>";    //zw  <button type='button' onclick='btn_Del(\"" + item.AttributeMapId +  "\");' class='btn btn-warning ng-binding'>删除</button>
                            + "</tr>";
                        }
                        else {
                            SMShtml += "<td   id=\"list" + (i + 1) + "\"></td>"
                            + "</tr>";
                        }

                    }


                    SMShtml += "</tbody></table>";
                    $("#AttributeList_div").html(SMShtml);
                },
                error: function (data, textStatus) {
                    alert("ajax错误");

                }

            });

        }
        function GetNNRelationship() {
            $.ajax({
                url: "/Service/Entity/GetRelationList.ashx",
                async: false,
                type: "post",
                dataType: "JSON",
                data: {
                    "entityid": $("#entityid").val()
                },
                success: function (data, textStatus) {

                    var SMShtml = "<table class='table table-hover'>"
                        + " <thead><tr><th>#</th><th>关系名</th><th>关联实体"
                                          + "</th><th>操作</th></tr></thead><tbody>";

                    for (var i = 0; i < data.length; i++) {

                        var item = data[i];
                        SMShtml += "<tr  name='list' id=\"" + (i + 1) + "\">"
                        /*NO*/ + "<td>" + (i + 1) + "</td>"
                    + "<td  id=\"list" + (i + 1) + "\">" + item.RelationName + "</td>"
                    + "<td   id=\"list" + (i + 1) + "\">" + item.EntityDisplayName + "</td>"
                    + "<td   id=\"list" + (i + 1) + "\"><button type='button' onclick='btn_DelRelation(\"" + item.RelationName + "\");' class='btn btn-warning ng-binding'>删除</button></td>"
                     + "</tr>";


                    }


                    SMShtml += "</tbody></table>";
                    $("#NNrelationship_div").html(SMShtml);
                },
                error: function (data, textStatus) {
                    alert("ajax错误");

                }

            });

        }
        function GetViewList() {
            $.ajax({
                url: "/Service/Entity/GetViewMapInfo.ashx",
                async: false,
                type: "post",
                dataType: "JSON",
                data: {
                    "EntityName": $("#entityName").html()
                },
                success: function (data, textStatus) {

                    var SMShtml = "<table class='table table-hover'>"
                        + " <thead><tr><th>#</th><th>视图名称</th><th>视图显示名称"
                                          + "</th><th>操作</th></tr></thead><tbody>";

                    for (var i = 0; i < data.length; i++) {

                        var item = data[i];
                        SMShtml += "<tr  name='list' id=\"" + (i + 1) + "\">"
                        /*NO*/ + "<td>" + (i + 1) + "</td>"
                    + "<td  id=\"list" + (i + 1) + "\">" + item.Name + "</td>"
                    + "<td   id=\"list" + (i + 1) + "\">" + item.DisplayName + "</td>"
                     + "<td   id=\"list" + (i + 1) + "\"><button type='button'  class='btn btn-primary ng-binding' onclick='btn_openView(\"" + item.Name + "\");'>查看</button>&nbsp;<button type='button' onclick='btn_delView(\"" + item.Name + "\");' class='btn btn-primary ng-binding'>删除</button></td>"
                     + "</tr>";
                    }
                    SMShtml += "</tbody></table>";
                    $("#ViewList_div").html(SMShtml);
                },
                error: function (data, textStatus) {
                    alert("ajax错误");

                }

            });
        }
        function GetFormList() {
            $.ajax({
                url: "/Service/Entity/GetFormInfo.ashx",
                async: false,
                type: "post",
                dataType: "JSON",
                data: {
                    "EntityName": $("#entityName").html()
                },
                success: function (data, textStatus) {

                    var SMShtml = "<table class='table table-hover'>"
                        + " <thead><tr><th>#</th><th>表单名称</th><th>表单显示名称"
                                          + "</th><th>操作</th></tr></thead><tbody>";

                    for (var i = 0; i < data.length; i++) {

                        var item = data[i];
                        SMShtml += "<tr  name='list' id=\"" + (i + 1) + "\">"
                        /*NO*/ + "<td>" + (i + 1) + "</td>"
                    + "<td  id=\"list" + (i + 1) + "\">" + item.FormName + "</td>"
                    + "<td   id=\"list" + (i + 1) + "\">" + item.DisplayName + "</td>"
                     + "<td   id=\"list" + (i + 1) + "\"><button type='button' onclick='btn_openForm(\"" + item.FormName + "\"," + item.FormType + ");' class='btn btn-primary ng-binding'>查看</button>&nbsp;<button type='button' onclick='if(confirm(\"确认删除？\")){ btn_delForm(\"" + item.FormName + "\");}' class='btn btn-primary ng-binding'>删除</button></td>"
                     + "</tr>";
                    }
                    SMShtml += "</tbody></table>";
                    $("#FormList_div").html(SMShtml);
                },
                error: function (data, textStatus) {
                    alert("ajax错误");

                }

            });
        }
        function btn_addAttribute() {
            window.location = "AddAttributePage.aspx?Id=" + $("#entityid").val();
        }
        function btn_return() {
            window.location = "EntityListPage.aspx";

        }
        function btn_updateEntity() {
            var update = {};
            update["EntityId"] = $("#entityid").val();
            update["EntityDisplayName"] = $("#alter_EntityDisplayName").val();
            update["Desc"] = $("#Desc").val();

            $.ajax({
                url: "/Service/Entity/UpdateEntity.ashx",
                async: false,
                type: "post",
                dataType: "JSON",
                data: {
                    "updateEntity": JSON.stringify(update)
                },
                success: function (data, textStatus) {
                    if (data.Result == "0") {
                        location.reload();
                    }
                    else {
                        alert(data.Remark);
                    }

                },
                error: function (data, textStatus) {
                    alert("错误");

                }

            });
        }
        function btn_openView(id) {
            //       alert($('.page-header').find('span[id=entityName]').html());

            window.location = "AddViewPage.aspx?Id=" + $("#entityid").val() + "&ViewMapName=" + id;

        }
        function btn_openDetail(id) {
            window.location = "AddAttributePage.aspx?Id=" + $("#entityid").val() + "&edit=1&AttributeId=" + id;
        }
        function btn_addNN() {
            window.location = "AddRelationPage.aspx?Id=" + $("#entityid").val();
        }
        function btn_addView() {
            window.location = "AddViewPage.aspx?Id=" + $("#entityid").val();
        }
        function btn_addForm() {
            $('#FormChoose').modal({ backdrop: 'static', keyboard: false });
            
        }

        function btn_addPcForm() {
            window.location = "EntityFormConfigPage.aspx?Id=" + $("#entityid").val() + "&entityname=" + $("#entityName").text();
        }

        function btn_addAppForm() {
            window.location = "EntityAppFormConfigPage.aspx?Id=" + $("#entityid").val() + "&entityname=" + $("#entityName").text();
        }

        function btn_delForm(formname) {
            $.ajax({
                url: "/Service/Entity/DeleteForm.ashx",
                async: false,
                type: "post",
                dataType: "text",
                data: {
                    "FormName": formname,
                    "EntityName": $("#entityName").html()
                },
                success: function (data) {
                    window.location = "AttributeListPage.aspx?Id=" + $("#entityid").val();
                },
                error: function (data) {
                    alert("ajax错误");
                }
            });
        }
        //zw btn_delView
        function btn_delView(viewname) {

            if (confirm("您确定要删除吗?")) {
                if (confirm("您确定真的要删除吗?")) {
                    if (confirm("您确定真的要真的要删除吗?")) {
                        $.ajax({
                            url: "/Service/Entity/DeleteView.ashx",
                            async: false,
                            type: "post",
                            dataType: "text",
                            data: {
                                "ViewName": viewname,
                                "EntityName": $("#entityName").html()
                            },
                            success: function (data) {
                                window.location.reload();
                                alert("删除成功");

                            },
                            error: function (data) {
                                alert("ajax错误");
                            }
                        });
                    }
                }
            }
        }
        //btn_DelRelation
        function btn_DelRelation(src) {
            if (confirm("您确定要删除吗?")) {
                if (confirm("您确定真的要删除吗?")) {
                    if (confirm("您确定真的要真的要删除吗?")) {

                        $.ajax({
                            url: "/Service/Entity/DeleteRelation.ashx",
                            async: false,
                            type: "post",
                            dataType: "text",
                            data: {
                                "relationname": src
                            },
                            success: function (data) {

                                window.location.reload();
                                alert("删除成功");

                            },
                            error: function (data) {
                                alert("ajax错误");
                            }
                        });
                    }

                }
            }
        }
        //zw-end
        function btn_openForm(formname, FormType) {
            if (FormType == 0) {
                window.location = "EntityFormConfigPage.aspx?Id=" + $("#entityid").val() + "&entityname=" + $("#entityName").text() + "&formname=" + formname;
            } else {
                window.location = "EntityAppFormConfigPage.aspx?Id=" + $("#entityid").val() + "&entityname=" + $("#entityName").text() + "&formname=" + formname;
            }
        }
        function btn_editEntityLink() {
            window.location = "EntityLinkPage.aspx?Id=" + $("#entityid").val() + "&etn=" + $("#entityName").text();
        }
        //zw
        function btn_keep(name, type) {
            Name = name;
            Type = type;

        }
        function btn_Del(Name, Type) {

            $.ajax({
                url: "/Service/Entity/DeleteAttribute.ashx",
                async: false,
                type: "post",
                dataType: "text",
                data: {
                    "AttributeName": Name,
                    "EntityName": $("#entityName").html(),
                    "type": Type
                },
                success: function (data) {
                    window.location = "AttributeListPage.aspx?Id=" + $("#entityid").val();

                },
                error: function (data) {
                    alert("ajax错误");

                }

            });

        }
        //zw-end

    </script>
    <style>
        .page-header {
            margin: 15px;
        }

            .page-header + .btn-primary {
                margin: 0px 15px 10px 5px;
            }

        .panel-heading {
            padding: 3px 15px;
            height: 40px;
            line-height: 34px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="">
            <div class="row">
                <div class="col-lg-12">
                    <input id="entityid" type="hidden" value="<%=_EntityId %>" />
                    <h1 class="page-header">实体：<span id="entityName"><%=entityName%></span>,<span id="entityDisplayName"><%= entityDisplayName%></span></h1>
                    <button type='button' style="float: right" id='Button1' class='btn btn-primary ng-binding' onclick="btn_return();">
                        返回实体列表</button>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            修改实体信息
                        <button type='button' style="float: right" id='Button2' class='btn btn-primary ng-binding' onclick="btn_updateEntity();">
                            修改</button>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="form-group">
                                <label for="EntityDisplayName">
                                    实体中文名</label>
                                <input type="text" class="form-control" id="alter_EntityDisplayName" value="<%= entityDisplayName %>" />
                            </div>
                            <div class="form-group">
                                <label for="Desc">
                                    备注</label>
                                <textarea class="form-control" rows="3" id="Desc"><%= desc %></textarea>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            多对多关系
                        <button type='button' style="float: right" id='Button3' class='btn btn-primary ng-binding' onclick="btn_addNN();">
                            ADD</button>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <div id="NNrelationship_div">
                                </div>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            字段列表
                        <button type='button' style="float: right" id='addAttribute' class='btn btn-primary ng-binding'
                            onclick="btn_addAttribute();">
                            ADD</button>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <div id="AttributeList_div">
                                </div>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            视图列表
                        <button type='button' style="float: right" id='addView' class='btn btn-primary ng-binding'
                            onclick="btn_addView();">
                            ADD</button>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <div id="ViewList_div">
                                </div>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            表单列表

                        <button type='button' style="float: right" id='addForm' class='btn btn-primary ng-binding'
                            onclick="btn_addForm();">
                            添加</button>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <div id="FormList_div">
                                </div>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            编辑关联列表
                        <button type='button' style="float: right" class='btn btn-primary ng-binding'
                            onclick="btn_editEntityLink();">
                            进入</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>


    <!--/modelstart-->

    <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">提示</h3>
                </div>
                <div class="modal-body">
                    <h4>您确定要删除吗?</h4>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
                    <button id="showModal_btn" class="btn btn-primary" data-dismiss="modal">删除</button>
                </div>
            </div>
        </div>
    </div>

    <div id="myModal2" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel2">提示</h3>
                </div>
                <div class="modal-body">
                    <h4>您真的确定要删除吗?</h4>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
                    <button id="showModal_btn2" class="btn btn-primary" data-dismiss="modal">删除</button>
                </div>
            </div>
        </div>
    </div>

    <div id="myModal3" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel3">提示</h3>
                </div>
                <div class="modal-body">
                    <h4>您真的真的确定要删除吗?</h4>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
                    <button id="showModal_btn3" class="btn btn-primary" data-dismiss="modal">删除</button>
                </div>
            </div>
        </div>
    </div>



    <div id="FormChoose" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h5 id="FormChooseLable">选择一个你需要的Form类型</h5>
                </div>
                <div class="modal-body">
                    <div class="btn-group btn-group-justified" role="group" aria-label="ChooseForm" style="height: 65px">
                        <a class="btn btn-default" role="button" data-dismiss="modal" onclick="btn_addAppForm()"><h5>一个适用于app的Form</h5></a>
                        <a class="btn btn-default" role="button" data-dismiss="modal" onclick="btn_addPcForm()"><h5>一个适用于PC端的Form</h5></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%-- <div id="myModalForm" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="myModalFormLable">提示</h3>
                    </div>
                    <div class="modal-body">
                        <h4>别乱来呀，小伙子，后果很严重的，快点关闭！！！</h4>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
                        <button id="showModalForm_btn" class="btn btn-primary" data-dismiss="modal">删除</button>
                    </div>
                </div>
            </div>
        </div>--%>
    <!--/modelend-->
</body>
</html>
